﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using WindowsGame1.CoreComponents;//had to add this for the camera to recognize what a sprite is

namespace WindowsGame1
{
    public class Camera
    {
        public Vector2 Position;

        public Camera(Vector2 position)
        {
            this.Position = position;
        }

        public Camera()
        {
            this.Position = Vector2.Zero;
        }

        public Matrix TransformMatrix
        {
            get
            {
                return Matrix.CreateTranslation(new Vector3(-Position, 0f));
            }
        }

        
        public void LockCamera()
        {
            Position.X = MathHelper.Clamp(Position.X,0,TileMapComponent.WidthInPixels - TileEngine.ViewPortWidth);
            Position.Y = MathHelper.Clamp(Position.Y,0,TileMapComponent.HeightInPixels - TileEngine.ViewPortHeight);
        }

        public void LockToSprite(Sprite sprite)
        {
            Position.X = sprite.Position.X + sprite.Center.X
            - (TileEngine.ViewPortWidth / 2);
            Position.Y = sprite.Position.Y + sprite.Center.Y
            - (TileEngine.ViewPortHeight / 2);
        }
    }
}
